package plp.prolog.parser;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;

public class TestStatusManager {
	private ArrayList<TestStatus> success;
	private ArrayList<TestStatus> error;
	
	public static final int TEST_OK  = 0;
	public static final int TEST_NOK = 1;
	
	public TestStatusManager() {
		success = new ArrayList<TestStatus>();
		error = new ArrayList<TestStatus>();
	}
	
	public void addStatus(String fileName, int status, String log) {
		TestStatus ts = new TestStatus();
		
		ts.fileName = fileName;
		ts.status   = status;
		ts.log      = log;
		
		switch (ts.status) {
			case TEST_NOK:
				error.add(ts);
				break;
			case TEST_OK:
				success.add(ts);
				break;
		}
	}
	
	/**
	 * 	Sucess..................... 3 file(s)
		Erros...................... 1 file(s)
	 */
	public String[] getSummary() {
		ArrayList<String> logs = new ArrayList<>();
		logs.add("\t\tSucess..................... " + success.size() + " file(s)");
		logs.add("\t\tErrors..................... " + error.size() + " file(s)");
		
		String[] ret = new String[logs.size()];
		
		for (int i = 0; i < logs.size(); i++) {
			ret[i] = logs.get(i);
		}
		
		return ret;
	}
	
	/**
	 * test_4_ok.txt ........................... OK
		test_4_ok.txt ........................... NOK
			| 
			|
			|
	 */
	public String[] getDetailedResult() {
		ArrayList<String> logs = new ArrayList<>();
		
		for (TestStatus ts : error) {		
			logs.add("\t\t" + ts.fileName + " ........................... NOK" );
			for (String s : ts.log.split("\\n")) {
				logs.add("\t\t\t| " + s);
			}
		}
		
		for (TestStatus ts : success) {
			logs.add("\t\t" + ts.fileName + " ........................... OK" );
		}
		
		String[] ret = new String[logs.size()];
		
		for (int i = 0; i < logs.size(); i++) {
			ret[i] = logs.get(i);
		}
		
		return ret;
	}
	
	private class TestStatus {
		private String fileName;
		private int status;
		private String log;
	}
}
